<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Document</title>
    <link rel="stylesheet" href="/ftl/css/bootstrap.min.css">
    <link rel="stylesheet" href="/ftl/css/laypage.css">

    <script src="/ftl/js/vue/vue.min.js"></script>
    <script src="/ftl/js/jquery/jquery.min.js"></script>
    <script src="/ftl/js/laypage/laypage.js"></script>
    <script src="/ftl/js/layer/layer.js"></script>


</head>
<body>
<div>
    ${Session["user"].username},欢迎登录
</div>
<div id="app" class="container">
    <form action="" class="form-inline" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">用户名称</label>
            <input type="text" id="username" name="username" class="form-control" placeholder="请输入要查询的用户名">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询用户</button>
        <button type="button" id="addUser" class="btn btn-danger">新增用户</button>
    </form>
    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <th>用户名</th>
                <th>年龄</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{item.username}}</td>
                <td>{{item.age}}</td>
                <td>
                    <a href="#" @click="editEvent(item.id)">编辑</a>
                    <a href="#" @click="delEvent(item.id)">删除</a>
                </td>
            </tr>
            </tbody>
            <tr>
                <#--分页-->
                <td colspan="3">
                    <div id="pagenav"></div>
                </td>
            </tr>
        </table>

    </div>

</div>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            result: []
        }
    });
    var getUserPageList = function (curr) {
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: '/getPage',
            data: {
                pageNum: curr || 1,
                pageSize: 5,
                username: $("#username").val()
            },
            success: function (msg) {
                app.result = msg.page;
                laypage({
                    cont: 'pagenav',
                    pages: msg.totalPage,
                    skin: '#DB7093',
                    first: '首页',
                    last: '最后一页',
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getUserPageList(obj.curr)
                        }
                    }
                })
            }
        })
    }
    var delEvent=function (id){
        layer.confirm('您确定要删除吗？',
            {btn:['是','否']},
        function(){
$.ajax({
    type:'post',
    dataType: 'json',
    url:'/del',
    data:{
        id
    },
    success: function (msg){
        getUserPageList();
        layer.msg('已经成功删除记录'+id,{icon:5});
    }
});
        })
    }
    getUserPageList();

    /*查询用户事件*/
    $("#findUser").click(function () {
        getUserPageList()
    })

    /*新增用户事件*/
    $("#addUser").click(function () {
        layer.open({
            type: 2,
            title: "添加用户",
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['1100px', '600px'],
            content: '/ftl/add.html',
            end: function () {
                getUserPageList();
            }
        });
    });

    /*修改用户信息*/
    var editEvent=function (id){
        layer.open({
            type:2,
            title: '编辑用户',
            fix: false,
            maxmin:true,
            shadeClose: true,
            area: ["1100px","600px"],
            content: '/editpage?id='+id,
            end: function (){
                getUserPageList();
            }
        })
    }

</script>
</body>
</html>